#pragma  once

#include "BasicType.h"
#include "Stream.h"
#include "CharacterList.h"
#include "SceneObject.h"
#include "Parser.h"
#include "DisplayList.h"
#include "TimelineObject.h"
#include "ActionRecord.h"
#include "As2VirtualMachine.h"

namespace LightPlayer {

	class LightAbstractRenderer;

	class LightFile : public Parser {
		LightAbstractRenderer*						m_pRenderer;

		Stream										m_Stream;
		CharacterList								m_CharacterList;
		pool<SceneObject>							m_ObjectPool;
		pool<TimelineObject>						m_TimelineObjectPool;
		DisplayList									m_DsiplayList;
		ActionList									m_ActionList;
		FrameLabelList								m_FrameLabelList;
		As2VM										m_As2VM;
		var_list_type								m_VarList;

		RECT										m_frameSize;
		float										m_frameRate;
		float										m_frameDuration;
		float										m_timeSinceLastFrame;
		uint32										m_frameNumber;
		uint32										m_Actualframe;
		bool										m_IsPlaying;
	
	public:
													LightFile();
				void								init();
													~LightFile();
				void								open(const char* FileName);

				void								update(float dt);
				void								draw();
				void								SetRenderer(LightAbstractRenderer* pRenderer)		{m_pRenderer = pRenderer;};
		virtual LightAbstractRenderer*				getRenderer()										{return m_pRenderer;}

	private:
		void										collectFrameLabels();
		void										clearDisplayList();
		// parser
		virtual Stream*								getParserStream()									{return &m_Stream;};
		virtual CharacterList*						getCharacterList()									{return &m_CharacterList;};
		virtual pool<SceneObject>*					getObjectPool()										{return &m_ObjectPool;};
		virtual pool<TimelineObject>*				getTimelineObjectPool()								{return &m_TimelineObjectPool;};
		virtual DisplayList*						getDisplayList()									{return &m_DsiplayList;};
		virtual ActionList*							getActionList()										{return &m_ActionList;};
		virtual As2VM*								getAs2VM()											{return &m_As2VM;};
		virtual uint32								getFrameNumber()									{return m_frameNumber;};
		virtual uint32								getActualFrame()									{return m_Actualframe;};
		virtual void								setActualFrame(uint32 frame)						{m_Actualframe = frame;}
		virtual SceneObject*						getNewSceneObject();
		virtual TimelineObject*						getNewTimelineObject();
		virtual void								freeObject(SceneObject* object);
		virtual uint16								getFrameForLabel(const char* label);
		// as2 function
		virtual bool								isPlaying() const									{return m_IsPlaying;}
		virtual void								play()												{m_IsPlaying = true;}
		virtual void								stop()												{m_IsPlaying = false;}
		virtual As2Var								getVar(const char* name);
		virtual void								setVar( const char* name, const As2Var& value );
		virtual As2Var								getProperty(PropertyEnum property);
		virtual void								setProperty(PropertyEnum property, const As2Var& value );
	};
	
};